import java.util.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-11-18
 * Time:20:54
 */
public class TestDemo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str = new String();
        str = sc.nextLine();

        //将字符串转换成字符数组
        char[] arr = str.toCharArray();
        //创建map集合，用来存放字符
        // 2,创建一个map集合,将字符和出现的次数存储到集合中，并排序
        TreeMap<Character, Integer> map = new TreeMap<Character, Integer>();
        // 3,遍历字符数组
        for (char c : arr) {
            map.put(c, map.get(c) != null ? map.get(c) + 1 : 1);
        }
        // 4,创建StringBuffer
        StringBuffer sb = new StringBuffer();
        // 5,遍历map集合
        for (int i = 0; i < str.length(); i++) {
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                char str_i = str.charAt(i);
                if(str_i == entry.getKey()) {
                    sb.append(entry.getKey()).append("(").append(entry.getValue()).append(")");
                    str = str.replaceAll(str_i+"","-1");
                    System.out.println(str.toString());
                    break;
                }
            }
        }

        //返回StringBuffer的字符串形式
        System.out.println(sb.toString());



    }
}
